#compdef cargo
typeset -A opt_args
+autoload -U regexp-replace
_cargo() {
'(- 1 *)'{-v,--verbose}'[use verbose output]' \
'(- 1 *)'{-V,--version}'[show version information]' \
'1: :_cargo_cmds' \
- '*:: :->args'
+ '*:: :->args'
case $state in
args)
#TODO: add path completion to manifest-path options
- case $words[1] in
+ case $words[1] in
bench)
_arguments \
'--features=[space separated feature list]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'[number of jobs to run in parallel]' \
'--manifest-path=[path to manifest]' \
- '--name=[benchmark name]: :_benchmark_names' \
+ '--bench=[benchmark name]: :_benchmark_names' \
'--no-default-features[do not build the default features]' \
'--no-run[compile but do not run]' \
- '(-p,--package)'{-p=,--package=}'[package to run benchmarks for]:_get_packages' \
+ '(-p,--package)'{-p=,--package=}'[package to run benchmarks for]:packages:_get_package_names' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
;;
'(-j, --jobs)'{-j,--jobs}'[number of jobs to run in parallel]' \
'--manifest-path=[path to manifest]' \
'--no-default-features[do not build the default features]' \
- '(-p,--package)'{-p=,--package=}'[package to build]:_get_packages' \
+ '(-p,--package)'{-p=,--package=}'[package to build]:packages:_get_package_names' \
'--release=[build in release mode]' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]' \
- '(-p,--package)'{-p=,--package=}'[package to build]:_get_packages' \
+ '(-p,--package)'{-p=,--package=}'[package to clean]:packages:_get_package_names' \
'--target=[target triple(default:all)]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
;;
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'[number of jobs to run in parallel]' \
'--manifest-path=[path to manifest]' \
- '--name=[name of the bin target]' \
+ '--bin=[name of the bin target]' \
'--no-default-features[do not build the default features]' \
'--release=[build in release mode]' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
;;
-
test)
_arguments \
'--features=[space separated feature list]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'[number of jobs to run in parallel]' \
'--manifest-path=[path to manifest]' \
- '--name=[test name]: :_test_names' \
+ '--test=[test name]: :_test_names' \
'--no-default-features[do not build the default features]' \
'--no-run[compile but do not run]' \
- '(-p,--package)'{-p=,--package=}'[package to run tests for]:_get_packages' \
+ '(-p,--package)'{-p=,--package=}'[package to run tests for]:packages:_get_package_names' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '1: :_test_names' \
;;
update)
'--aggressive=[force dependency update]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]' \
- '(-p,--package)'{-p=,--package=}'[package to run tests for]:_get_packages' \
+ '(-p,--package)'{-p=,--package=}'[package to update]:packages:__get_package_names' \
'--precise=[update single dependency to PRECISE]: :_test_names' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
;;
;;
esac
;;
-esac
+esac
}
_cargo_cmds(){
}
-#TODO:parse Cargo.toml for package names
-_get_packages(){
-local -a packages;packages=(
-)
+#gets package names from the manifest file
+_get_package_names(){
+local manifest=$(_locate_manifest)
+local -a packages;packages=()
+if ! [[ $manifest ]]; then
+ return 0
+fi
+
+while read line
+do
+ if [[ $line =~ '^.*dependencies' ]]; then
+ regexp-replace line '^.*dependencies\.|\]' ''
+ packages+=$line
+ fi
+ last_line=$line
+done < $manifest
_describe 'packages' packages
}
_describe 'tests' tests
}
-#TODO:parse Cargo.toml for test names
+#TODO:see if it makes sense to have 'locate-project' to have non-json output.
+#strips package name from json stuff
+_locate_manifest(){
+local manifest=`cargo locate-project 2>/dev/null`
+regexp-replace manifest '\{"root":"|"\}' ''
+echo $manifest
+}
+
+#gets test names from the manifest file
_test_names(){
-local -a tests;tests=(
-)
+local -a filelist;
+local manifest=$(_locate_manifest)
+if ! [[ $manifest ]]; then
+ return 0
+fi
+
+local last_line
+local -a tests;
+tests=()
+while read line
+do
+ if [[ $last_line == '[[test]]' ]]; then
+ regexp-replace line '^.*name *= *|"' ""
+ tests+=$line
+ fi
+ last_line=$line
+done < $manifest
_describe 'tests' tests
}